<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
 	session.setAttribute("stage", "2");
	request.setCharacterEncoding("UTF-8");
%>

<%@page import="java.util.*" %>
<%@page import="member.MemberBean" %>

<%
	@SuppressWarnings("unchecked")
	ArrayList<MemberBean> list = (ArrayList<MemberBean>)request.getAttribute("list");
	//表示メッセージを取得
	String msg = (String)request.getAttribute("msg");
//	String rmsg = (String)request.getAttribute("rmsg");
	Integer crtPage = (Integer)request.getAttribute("page");

	//件数カウント情報を取得
	Integer cnt = (Integer)request.getAttribute("cnt");

	//件数メッセージを取得
	String cntmsg = (String)request.getAttribute("cntmsg");

	// ページングURLの取得
	//	String pageUrl = request.getQueryString();
	//	System.out.println("URLcheck:"+pageUrl);
	//	int index = pageUrl.indexOf("&page=");
	//	System.out.println(index);
	//	pageUrl = pageUrl.substring(0,index);

	@SuppressWarnings("unchecked")
	Map<String, String[]> m = (Map<String, String[]>)session.getAttribute("MemberSerchParameter");
	String[] urls = (String[])m.get("url");
	// ページングURLの取得
	String pageUrl = request.getQueryString();
	if (pageUrl != null) {
		int index = pageUrl.indexOf("&page=");
		if (index < 0) {
			pageUrl = urls[0];
		}
		else {
			pageUrl = pageUrl.substring(0,index);
		}
	}
	else {
		pageUrl = urls[0];
	}
	// ページ表示件数を取得
	int max = MemberBean.PAGE_MAX;
%>

<link href="common.css" rel="stylesheet" type="text/css">

<c:import url="/share/layout.jsp" >
    <c:param name="title" value="利用者検索結果"/>
    <c:param name="css" value="booksearch.css"/>
    <c:param name="css" value="common.css"/>
    <c:param name="content">
        <jsp:attribute name="value">

<!-- contents start -->

<% if(msg != null && !"".equals(msg)) { %>
<div id="msg_area">
	<%= msg %>

</div>
	<%} %>

<div id="search">

	<% if(cnt == 0) { %>
<%-- 		<p class="error_message"><%= rmsg %></p> --%>
	<% } else if(cnt != 0) { %>
		<p id="result"><strong><%= cntmsg %></strong> </p>
	<% } %>



</div>

<form id="mng_form" action="/Books/member/MenuServlet">
		<table class="list_table">
			<thead>
				<tr>
				  <th id="id" colspan="2">利用者ID</th>
					<th id="name">氏名</th>
					<th id="title">フリガナ</th>
					<th id="writer">メールアドレス</th>
				</tr>
			</thead>
			<tbody>
				<%
				for ( int i=0 ; i<list.size() ; i++ ) {
					MemberBean mb = list.get(i);

				%>
				<tr>
				  <td align="center"><input type="radio" name="id" value="<%= mb.getId() %>" /></td>
                    <td align="center"><%= mb.getId() %></td>



					<td><%= mb.getName() %></td>
					<td><%= mb.getRuby() %></td>
					<td><%= mb.getUserId() %></td>
				</tr>
				<%
				}
				%>

			</tbody>
		</table>

	<div id="paging_area">
		<%
			double dMax = cnt / (double)max;
			int maxPage = (int)Math.ceil(dMax);
		%>
		<%= crtPage %> / <%= maxPage %><br />
		<%
			if(maxPage > 1) {
				String linkPage = "/Books/member/UserMemberSearchServlet?" + pageUrl + "&page=";
				if(crtPage > 1) {
					int p = crtPage - 1;
					out.println("<a href=\"" + linkPage + p + "\">前へ</a>");
				}
				for(int i=0, p=1; i<cnt; i+=max, p++) {
					//out.println("<a href=" + ">" + p + "</a>");
	 			out.println("<a href=\"" + linkPage + p + "\">" + p + "</a>");


				}
				if(crtPage * max < cnt) {
					int p = crtPage + 1;
					out.println("<a href=\"" + linkPage + p + "\">次へ</a>");
				}
			}
		%>
	</div>

<input type="hidden" name="url" value="<%=request.getQueryString() %>" />

<div id="button">
<!-- 『戻る』ボタンをtype="submit"からtype="button"に変更【20131017_矢野】 -->
<!--  <input class="button" type="button" value="戻る"  onClick="history.back(); return false;" /> -->
<!-- 『登録』ボタンを『新規登録』に変更【20131017_矢野】 -->
<!-- 『戻る』ボタンをtype="button"からtype="submit"に変更【20131016_若林】 -->
  <input class="button" type="submit" name="back" value="戻る">
  <input class="button" type="submit" name="delete" value="削除">
  <input class="button" type="submit" name="edit"   value="変更">
  <input class="button" type="submit" name="entry"  value="新規登録">
</div>
</form>

<!-- contents end -->
        </jsp:attribute>
    </c:param>
</c:import>
